package com.CST.controller.ys;

import com.CST.common.StaticVariable;
import com.CST.common.api.ResultObject;
import com.CST.dto.ys.YsComplaintDTO;
import com.CST.entity.ys.YsComplaint;
import com.CST.service.ys.YsComplaintService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qtx
 * @since 2023-05-15
 */
@Api(tags = "消息中心")
@RestController
@RequestMapping("/ysComplaint")
public class YsComplaintController {

    public final YsComplaintService service;
    public YsComplaintController(YsComplaintService service) {
        this.service = service;
    }

    @ApiOperation("分页查询")
    @PostMapping("/listYsComplaintPage")
    public ResultObject<Page<YsComplaint>> listYsComplaintPage(@RequestBody YsComplaintDTO dto){
        return ResultObject.success(service.listYsComplaintPage(dto));
    }

    @ApiOperation("未读信息")
    @GetMapping("/online")
    public ResultObject<List<YsComplaint>> online(){
        return ResultObject.success(service.online());
    }

    @ApiOperation("未读变已读")
    @GetMapping("/updateYsComplaint")
    public ResultObject<Boolean> updateYsComplaint(Long id){
        return ResultObject.success(service.updateYsComplaint(id));
    }

    @GetMapping("/test")
    public void test(String name){
        service.saveEntity(YsComplaint.builder()
                .recipient(StaticVariable.LOG_YS_COMPLAINT_RECIPIENT_2)
                .source(StaticVariable.LOG_YS_COMPLAINT_SOURCE_1)
                .operate(StaticVariable.LOG_YS_COMPLAINT_OPERATE_1)
                .acceptContent("<span class=\"resolve\">已修正</span>后勤部" + "对" + "(11022)" + StaticVariable.LOG_YS_COMPLAINT_CONTEXT_1)
                .jumpPage(StaticVariable.LOG_YS_COMPLAINT_PAGE_2)
                .complaintUser(name)
                .build());
    }
}
